package com.tiancan.design.message.service.impl;

import com.tiancan.design.message.service.SendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/** @author tiancan */
@Service
public class EmailSendServiceImpl implements SendService {
  @Autowired private JavaMailSender javaMailSender;

  @Value("${spring.mail.username}")
  private String formEmail;

  @Override
  public boolean sendMessage(String email, String title, String content) {
    SimpleMailMessage message = new SimpleMailMessage();
    message.setFrom(formEmail);
    message.setTo(email);
    message.setSubject(title);
    message.setText(content);
    try {
      javaMailSender.send(message);
    } catch (Exception ex) {
      ex.printStackTrace();
      return false;
    }
    return true;
  }
}
